package part3.student;

import java.util.ArrayList;

public class Handle {
    private static ArrayList list=new ArrayList();
    //添加学生信息
    public static boolean AddInfo(Info add_info) {
        boolean add=false;
        add=list.add(add_info);
        return add;
    }
    //根据学号修改学生信息
    public static boolean updateInfoById(int id, Info update_infoById) {
        boolean update=false;
        for(Object obj:list){
            Info info=(Info)obj;
            if(id==info.getStu_id()){
                list.set(list.indexOf(info), update_infoById);
                update=true;
                break;
            }
        }
        return update;
    }

    //根据姓名修改学生信息
    public static boolean updateInfoByName(String name, Info update_infoByName) {
        boolean update=false;
        for(Object obj:list){
            Info info=(Info)obj;
            if(name.equals(info.getStu_name())){
                list.set(list.indexOf(info), update_infoByName);
                update=true;
                break;
            }
        }
        return update;
    }

    //根据学号删除学生信息
    public static boolean deleteInfoById(int delete_id) {
        boolean delete=false;
        for(Object obj:list){
            Info info=(Info)obj;
            if(delete_id==info.getStu_id()){
                delete=list.remove(info);
                break;
            }
        }
        return delete;
    }


    //根据姓名删除信息
    public static boolean deleteInfoByName(String delete_name) {
        boolean delete=false;
        for(Object obj:list){
            Info info=(Info)obj;
            if(delete_name.equals(info.getStu_name())){
                delete=list.remove(info);
                break;
            }
        }
        return delete;
    }


    //查询所有学生信息
    public static void selectAllInfo() {
        for(Object obj:list){
            Info info=(Info)obj;
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append("学号:"+info.getStu_id());
            stringBuilder.append("\t姓名:"+info.getStu_name());
            stringBuilder.append("\t性别:"+info.getStu_sex());
            stringBuilder.append("\t年龄:"+info.getStu_age());
            stringBuilder.append("\n语文成绩:"+info.getChinese());
            stringBuilder.append("\t数学成绩:"+info.getMath());
            stringBuilder.append("\t英语成绩:"+info.getEnglish());
            stringBuilder.append("\t平均成绩:"+info.getAvgScose());
            stringBuilder.append("\t总成绩:"+info.getSunScose());
            stringBuilder.append("\n地址:"+info.getStu_address()+"\n");
            System.out.println(stringBuilder.toString());
        }

    }

    //根据学号查询信息
    public static Info selectInfoById(int select_id) {
        Info in=null;
        for(Object obj:list){
            Info info=(Info)obj;
            if(select_id==info.getStu_id()){
                System.out.println("\n该学生信息如下:\n");
                StringBuilder stringBuilder=new StringBuilder();//同上
                stringBuilder.append("学号:"+info.getStu_id());
                stringBuilder.append("\t姓名:"+info.getStu_name());
                stringBuilder.append("\t性别:"+info.getStu_sex());
                stringBuilder.append("\t年龄:"+info.getStu_age());
                stringBuilder.append("\n语文成绩:"+info.getChinese());
                stringBuilder.append("\t数学成绩:"+info.getMath());
                stringBuilder.append("\t英语成绩:"+info.getEnglish());
                stringBuilder.append("\t平均成绩:"+info.getAvgScose());
                stringBuilder.append("\t总成绩:"+info.getSunScose());
                stringBuilder.append("\n地址:"+info.getStu_address()+"\n");
                System.out.println(stringBuilder.toString());
                in=info;
            }
        }
        return in;
    }

    //根据姓名查询信息
    public static Info selectInfoByName(String select_name) {
        Info in=null;
        for(Object obj:list){
            Info info=(Info)obj;
            if(select_name.equals(info.getStu_name())){
                StringBuilder stringBuilder=new StringBuilder();
                stringBuilder.append("学号:"+info.getStu_id());
                stringBuilder.append("\t姓名:"+info.getStu_name());
                stringBuilder.append("\t性别:"+info.getStu_sex());
                stringBuilder.append("\t年龄:"+info.getStu_age());
                stringBuilder.append("\n语文成绩:"+info.getChinese());
                stringBuilder.append("\t数学成绩:"+info.getMath());
                stringBuilder.append("\t英语成绩:"+info.getEnglish());
                stringBuilder.append("\t平均成绩:"+info.getAvgScose());
                stringBuilder.append("\t总成绩:"+info.getSunScose());
                stringBuilder.append("\n地址:"+info.getStu_address()+"\n");
                System.out.println(stringBuilder.toString());
                in=info;
            }
        }
        return in;
    }

    //得到学号
    public static boolean selectStuId(int id) {
        boolean fag=false;
        for(Object obj:list){
            Info info=(Info)obj;
            if(id==info.getStu_id()){
                fag=true;
                break;
            }
        }
        return fag;
    }

    //得到姓名
    public static boolean selectStuName(String name){
        boolean fag=false;
        for(Object obj:list){
            Info info=(Info)obj;
            if(name.equals(info.getStu_name())){
                fag=true;
                break;
            }
        }
        return fag;
    }


}
